import { createSlice } from '@reduxjs/toolkit';

const initialState = {
  paramsData: {}, // 存储第二次预测返回的后端数据
  predictedWater: null, // 来料水分预测值
  dehydrationAmount: null, // 脱水量
};

const paramsSlice = createSlice({
  name: 'params',
  initialState,
  reducers: {
    // 更新第二次预测数据
    updateParamsData(state, action) {
      state.paramsData = action.payload;
    },
    // 更新来料水分预测值和脱水量
    updateWaterPrediction(state, action) {
      const { predictedWater, dehydrationAmount } = action.payload;
      state.predictedWater = predictedWater;
      state.dehydrationAmount = dehydrationAmount;
    },
    // 清空所有数据
    clearParamsData(state) {
      state.paramsData = {};
      state.predictedWater = null;
      state.dehydrationAmount = null;
    },
  },
});

export const { updateParamsData, updateWaterPrediction, clearParamsData } = paramsSlice.actions; // 导出 actions
export default paramsSlice.reducer; // 导出 reducer
